' 
' Copyright (C) 2014 Infinity CCS Ltd (http://www.infinityccs.com/)
' Copyright (C) 2008 Sasa Coh <sasacoh@gmail.com>
'
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program.  If not, see <http://www.gnu.org/licenses/>. 
'/

Imports System
Imports Infinity.pjsipNET.Common.Config

Namespace Common.Presence
  ''' <summary>
  ''' Abstract class for presence and instant messaging handling
  ''' </summary>
  Public MustInherit Class IPresenceAndMessaging
#Region "Events"
    ''' <summary>
    ''' Buddy status changed notifier
    ''' </summary>
    Public Event BuddyStatusChanged(buddyId As Integer, status As Integer, text As String)
    ''' <summary>
    ''' Message received notifier
    ''' </summary>
    Public Event MessageReceived(from As String, text As String)
#End Region

#Region "Properties"
    Private _config As IConfigurator = New NullConfigurator()
    Public Property Config As IConfigurator
      Get
        Return _config
      End Get
      Set(value As IConfigurator)
        _config = value
      End Set
    End Property
#End Region

#Region "Public Methods"
    ''' <summary>
    ''' Add buddy to buddy list and subscribe presence
    ''' </summary>
    ''' <param name="ident">buddy identification</param>
    ''' <returns></returns>
    Public MustOverride Function addBuddy(ident As String, presence As Boolean, accountKey As String) As Integer
    ''' <summary>
    ''' Add buddy to buddy list and subscribe presence
    ''' </summary>
    ''' <param name="ident">Buddy identification</param>
    ''' <param name="presence">Flag if buddy is to subscribe sip presence</param>
    ''' <returns></returns>
    Public Function addBuddy(ident As String, presence As Boolean) As Integer
      Return Me.addBuddy(ident, presence, Config.DefaultAccountKey)
    End Function

    ''' <summary>
    ''' Delete buddy with given identification
    ''' </summary>
    ''' <param name="buddyId">buddy identification</param>
    ''' <returns></returns>
    Public MustOverride Function delBuddy(buddyId As Integer) As Integer

    ''' <summary>
    ''' Send Instant Message
    ''' </summary>
    ''' <param name="destAddress">Destination part of URI</param>
    ''' <param name="message">Message Content</param>
    ''' <returns></returns>
    Public MustOverride Function sendMessage(destAddress As String, message As String) As Integer

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="destAddress"></param>
    ''' <param name="message"></param>
    ''' <param name="accountKey"></param>
    ''' <returns></returns>
    Public MustOverride Function sendMessage(destAddress As String, message As String, accountKey As String) As Integer

    ''' <summary>
    ''' Set device status for default account 
    ''' </summary>
    ''' <param name="accountKey">Account id</param>
    ''' <param name="presence_state">Presence state - User Status</param>
    ''' <returns></returns>
    Public MustOverride Function setStatus(accountKey As String, presence_state As EUserStatus) As Integer
#End Region

#Region "Private Methods"
    ''' <summary>
    ''' MessageReceived event trigger by VoIP stack when instant message arrived
    ''' </summary>
    Protected Sub BaseMessageReceived(from As String, text As String)
      RaiseEvent MessageReceived(from, text)
    End Sub
    ''' <summary>
    ''' BuddyStatusChanged event trigger by VoIP stack when buddy status changed
    ''' </summary>
    Protected Sub BaseBuddyStatusChanged(buddyId As Integer, status As Integer, text As String)
      RaiseEvent BuddyStatusChanged(buddyId, status, text)
    End Sub
#End Region
  End Class

End Namespace
